from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
import time

d = webdriver.Chrome()
d.get('http://192.168.0.125:9009/')
time.sleep(1)

# 隐式等待
d.implicitly_wait(10)

# 最大化窗口
d.maximize_window()

# 下拉条
js = "window.scrollTo(0,1000);"
d.execute_script(js)
time.sleep(1)

# 点击登录按钮
dd_ele = d.find_element(By.XPATH, '/html/body/div/div/div/aside/section[6]/ul/li[2]/a')
dd_ele.click()
time.sleep(1)

# 输入账号
y_ele = d.find_element(By.CSS_SELECTOR, 'input[name="log"]')
y_ele.send_keys('admin')
time.sleep(1)

# 输入密码
m_ele = d.find_element(By.CSS_SELECTOR, 'input[name="pwd"]')
m_ele.send_keys('admin123')
time.sleep(1)

# 点击登录按钮
d_ele = d.find_element(By.CSS_SELECTOR, 'input[name="wp-submit"]')
d_ele.click()
time.sleep(1)

# 鼠标在文章上悬停
wz_ele = d.find_element(By.LINK_TEXT, '文章')
ActionChains(d).move_to_element(wz_ele).perform()
time.sleep(3)

# 点击所有文章
xwz_ele = d.find_element(By.LINK_TEXT, '所有文章')
xwz_ele.click()
time.sleep(2)

# 第一个元素  第二个元素  第三个元素
# find_element() 返回的 第一个元素
# find_elements() 返回的所有元素的列表  [第一个元素,第二个元素,第三个元素]

box = d.find_elements(By.CSS_SELECTOR, '[name="post[]"]')

for i in box:
    i.click()
    time.sleep(0.5)

time.sleep(5)
d.quit()
